// https://leetcode.cn/problems/zigzag-conversion/description/?envType=study-plan-v2&envId=top-interview-150

class Solution {
public:
    string convert(string s, int numRows) {
        if (numRows < 2) return s;
        
        vector<string> strs(numRows);
        int index = 0, flag = -1;

        for (char ch : s) {
            if (index == 0 || index == numRows - 1) {
                flag = -flag;
            }
            strs[index].push_back(ch);
            index += flag;
        }

        string ans = "";
        for (int i = 0; i < numRows; i++) {
            ans += strs[i];
        }
        return ans;
    }
};